home *** CD-ROM | disk | FTP | other *** search
- unit CopyAFile2Form;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- btnCopy: TButton;
- dlgSource: TOpenDialog;
- procedure btnCopyClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- uses
- ShellAPI, ShlObj;
-
- procedure FileCopy(const Source, Target: String);
- var
- FOS: TSHFileOpStruct;
- SourceLst: String;
- begin
- FillChar(FOS, SizeOf(FOS), 0);
- FOS.Wnd := Application.MainForm.Handle;
- FOS.wFunc := FO_COPY;
- //File name list must have 2 null terminators. It
- //gets 1 anyway. The other we pass in explicitly
- SourceLst := Source + #0;
- FOS.pFrom := PChar(SourceLst);
- FOS.pTo := PChar(Target);
- //Uncomment these 2 lines if you do not want the file
- //name details shown on the copy progress dialog
- //FOS.fFlags := FOF_SIMPLEPROGRESS;
- //FOS.lpszProgressTitle := 'Please wait...'
- SHFileOperation(FOS);
- end;
-
- function GetFolder: String;
- var
- BrowseInfo: TBrowseInfo;
- Folder: array[0..MAX_PATH] of Char;
- begin
- FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);
- BrowseInfo.hwndOwner := Application.MainForm.Handle;
- BrowseInfo.lpszTitle := 'Select destination folder';
- BrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS or BIF_DONTGOBELOWDOMAIN;
- SHGetPathFromIDList(SHBrowseForFolder(BrowseInfo), Folder);
- Result := Folder;
- end;
-
- procedure TForm1.btnCopyClick(Sender: TObject);
- var
- TargetFolder: String;
- begin
- if dlgSource.Execute then
- begin
- TargetFolder := GetFolder;
- if TargetFolder <> '' then
- FileCopy(dlgSource.FileName, TargetFolder)
- end
- end;
-
- end.
-